package com.xbs.controller.hitchhiking;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.controller.enterprise.DateJsonValueProcessor;
import com.xbs.entity.CommonOrderEntity;
import com.xbs.entity.OrderMoney;
import com.xbs.entity.RentEntity;
import com.xbs.entity.TimeEntity;
import com.xbs.service.hitchhiking.ChaKanXiangQingService;
import com.xbs.service.hitchhiking.HitchOrderAdminService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
/**
 * 后台顺风车查看详情
 * @author dell
 */
@WebServlet("/backstage/chakanajax")
public class ChaKanAjaxServlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		ChaKanXiangQingService cxqs = new ChaKanXiangQingService();
		
		/**
		 * 根据订单编号进行取车修改
		 */
		String id = req.getParameter("fid");
		TimeEntity time = cxqs.getTime(id);
		OrderMoney om = cxqs.getMoney(id);
		RentEntity rent = cxqs.getRent(id);
		CommonOrderEntity coe = cxqs.getOrder(id);
		System.out.println(time);
		JsonConfig jsonConfig = new JsonConfig();   
		jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   
		jsonConfig.registerJsonBeanProcessor(java.sql.Date.class, new DateJsonValueProcessor());  
		jsonConfig.setExcludes(new String[]{"handler","hibernateLazyInitializer"});    
		//JSONArray jsonArray = JSONArray.fromObject(xgemp.getIst(),jsonConfig);
		JSONObject obj1 = JSONObject.fromObject(time,jsonConfig);
		JSONObject obj2 = JSONObject.fromObject(om,jsonConfig);
		JSONObject obj3 = JSONObject.fromObject(rent,jsonConfig);
		JSONObject obj4 = JSONObject.fromObject(coe,jsonConfig);
		JSONArray jsonArray = new JSONArray();
		jsonArray.add(obj1);
		jsonArray.add(obj2);
		jsonArray.add(obj3);
		jsonArray.add(obj4);
		resp.getWriter().print(jsonArray);
	}
}
